package com.elephant.core.socket.socket1;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 1、客户端写服务端读
 * @author hai
 * @description
 * @date 10:42 2018/8/31
 */
public class Server {

    public static void main(String[] args) throws IOException {

        int port = 8888;
        ServerSocket server = new ServerSocket(port);
        Socket accept = server.accept();
        Reader reader = new InputStreamReader(accept.getInputStream());

        char[] chars = new char[64];
        int len;
        StringBuilder sb = new StringBuilder();
        while ((len = reader.read(chars)) != -1){
            sb.append(new String(chars,0,len));
        }

        System.out.println("From Client:" + sb);
        reader.close();
        accept.close();
        server.close();
    }
}
